Eshop::Application.routes.draw do

  #FRONTEND
  resource :user,          :path => "zakaznik", :path_names => {:new => "registrace", :edit => "editace"}
  resource :user_sessions, :path => "login",    :path_names => {:new => "prihlaseni"}
#  resources :authentications, :path => "auth" do
#    get :failure, :on => :member
#  end

  #Model versions
  match "/admin/verze/:id/vratit" => "admin/versions#revert", :as => :revert_version

  #Logging in
  match "/prihlaseni" => "user_sessions#new",     :as => :login
  match "/odhlaseni"  => "user_sessions#destroy", :as => :logout

  match "/auth/:provider/callback" => "authentications#callback"
  resources :authentications, :path => "auth"
  
  #BACKEND
  match "/admin" => "admin/admin#index"

  namespace "admin" do
    resources :versions, :path => "verze", :only => [:show, :revert, :destroy]
    scope "zakaznici" do
      resources :order_user_infos, :path => "prehled", :only => [:show, :index]
      resources :user_infos, :path => "registrovani", :path_names => {:edit => "editace", :new => "novy"}
    end
    resources :orders, :path => "objednavky", :path_names => {:edit => "editace"}
    scope "vyrobky" do
      resources :metrics, :path => "jednotky", :path_names => {:new => "nova", :edit => "editace"}
      resources :tax_categories, :path => "danove-skupiny", :path_names => {:new => "nova", :edit => "editace"}
      resources :amount_types, :path => "typy-mnozstvi", :path_names => {:new => "novy", :edit => "editace"}
      resources :parameters, :path => "volitelne-parametry", :path_names => {:edit => "editace", :new => "novy"}
      #resources :prototypes, :path => "sablony-vyrobku", :path_names => {:edit => "editace", :new => "nova"}
      resources :property_patterns, :path => "sablony-vlastnosti", :path_names => {:edit => "editace", :new => "nova"} do
        collection do
          get  'new_property_attribute', :path => 'novy-parametr'
          get  'new_property', :path => 'nova-skupina-parametru'
          post 'restructure', :path => 'prenastavit'
        end
      end
      #resources :property_groups, :path => "skupiny-vlastnosti", :path_names => {:edit => "editace", :new => "nova"} do
      resources :properties, :path => "skupiny-vlastnosti", :except => [:new, :create] do
        collection do
          get 'autocomplete_property_presentation'
          get 'autocomplete_property_attribute_presentation'
          get 'autocomplete_property_value_value'
        end
      end
    end
    resources :products, :path => "vyrobky", :path_names => {:edit => "editace", :new => "novy"} do
      member do
        get 'revive', :path => "obnovit"
        get 'clone',  :path => "klonovat"
      end
      resources :product_photos, :path => "fotky", :path_names => {:edit => "editace", :new => "nova"} do
        member do
          get 'move', :path => "presunout"
        end
      end
      resources :variants, :path => "varianty", :path_names => {:edit => "editace", :new => "nova"}
      resource  :product_categories, :path => "kategorie", :path_names => {:edit => "editace"}, :only => [:edit, :update, :show]
      resource  :product_parameters, :path => "parametry", :path_names => {:edit => "editace"}, :only => [:edit, :update, :show]
      resource  :product_properties, :path => "vlastnosti", :path_names => {:edit => "editace", :new => "nova"} do
          collection do
            get  'new_property_attribute', :path => 'novy-parametr'
            get  'new_property', :path => 'nova-skupina-parametru'
            get  'add_property_pattern', :path => 'pouzit-sablonu-vlastnosti'
            post 'restructure', :path => 'prenastavit'
          end
      end
      resources :product_supplements, :path => "prilohy", :path_names => {:edit => "editace", :new => "nova"} do
        member do
          get 'move', :path => "presunout"
        end
      end
      resource  :product_accessories, :path => "prislusenstvi" do
        member do
          get 'select', :path => 'zvolit'
          get 'remove', :path => 'odstranit'
        end
        collection do
          get 'available', :path => 'dostupne'
        end
      end
    end
    resources :comments, :path => "komentare", :only => [:create, :destroy]
    resources :category_groups, :path => "skupina-kategorii", :path_names => {:edit => "editace", :new => "nova"} do
      resources :categories, :path => "kategorie", :path_names => {:edit => "editace", :new => "nova"}
      collection do
        post 'restructure', :path => 'prenastavit'
      end
    end
    
    scope "nastaveni" do
      scope "administratori" do
        resources :roles, :path => "prava", :path_names => {:new => "nove", :edit => "editace"}
      end
      scope "sablony" do
        resources :templates, :path => "systemove", :path_names => {:new => "nova", :edit => "editace"}
        resources :email_templates, :path => "emailove", :path_names => {:new => "nova", :edit => "editace"}
      end
      resources :contents, :path => "texty", :path_names => {:new => "novy", :edit => "editace"}
      
      resources :administrators, :path => "administratori", :path_names => {:new => "novy", :edit => "editace"}
      resources :shipping_methods, :path => "metody-doruceni", :path_names => {:edit => "editace"}, :except => [:new, :create]
      resources :billing_methods, :path => "metody-placeni", :path_names => {:edit => "editace"}, :except => [:new, :create]
    end
    resource  :setting, :path => "nastaveni", :only => [:show, :update]
  end

  match "/:main_category(/*categories)" => "categories#index", :as => :category
  
  #DEFAULT
  root :to => "templates#template", :template_name => "index"
  
  #match '*a', :to => 'errors#not_found'
end
